package com.yehui.algorithm.sword;

/**
 * Created by XuChunH on 2016/9/18.
 */
public class SymmetricalBTree {

    public boolean solution(TreeNode pRoot) {
        if (pRoot == null) {
            return true;
        }
        return compare(pRoot.left, pRoot.right);
    }

    private boolean compare(TreeNode left, TreeNode right) {
        if(left == null) {
            return right == null;
        }
        if(right == null) {
            return false;
        }
        if(left.val != right.val) {
            return false;
        }
        return compare(left.left, right.right) && compare(left.right, right.left);
    }

}
